{% extends "kbforums/base.html" %}
{# L10n: {l} is the name of the locale. #}
{% set title = _('{locale_name} Discussions | Knowledge Base')|f(locale_name=locale_name) %}
{% set crumbs = [(None, _('{locale_name} Discussions')|f(locale_name=locale_name))] %}

{% block content %}
  <div class="grid_9">
    <article id="threads" class="content-box">
      <h1>{{ _('{l} Knowledge Base Discussions')|f(l=locale_name) }}</h1>
      {% if user.is_authenticated() %}
        <form id="watch_locale" action="{{ url('wiki.discuss.watch_locale') }}" method="post">
          {% csrf_token %}
          <input type="hidden" name="next" value="{{ request.get_full_path() }}">
          {% if is_watching_locale %}
            {% set watch = _('Stop watching this locale') %}
            <input type="hidden" name="watch" value="no">
          {% else %}
            {% set watch = _('Watch this locale') %}
            <input type="hidden" name="watch" value="yes">
          {% endif %}
          <button type="submit" alt="{{ watch }}" title="{{ watch }}" class="btn" id="watch-forum-toggle"><img src="{{ STATIC_URL }}sumo/img/blank.png" alt="" /> {{ watch }}</button>
        </form>
      {% endif %}
      <ol class="threads-columns cf {% if not desc_toggle %}desc{% endif %}">
        {% if user.is_authenticated() %}
          <li class="watch">{{ _('Watch') }}</li>
        {% endif %}
        <li class="title">{{ _('Title') }}</li>
        <li class="author{% if sort == 3 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=3, desc=desc_toggle) }}">{{ _('Author') }}</a></li>
        <li class="replies{% if sort == 4 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=4, desc=desc_toggle) }}">{{ _('Replies') }}</a></li>
        <li class="last-post{% if sort == 5 %} sort{% endif %}"><a href="{{ request.path|urlparams(sort=5, desc=desc_toggle) }}">{{ _('Last Post') }}</a></li>
      </ol>
      {% if threads.object_list %}
        <ol class="threads">
        {% for thread in threads.object_list %}
          <li class="cf">
            {% if user.is_authenticated() %}
              <div class="watch">
                <form class="watch-form" action="{{ url('wiki.discuss.watch_thread', thread.document.slug, thread.id) }}" method="post">
                    {% csrf_token %}
                    {% if thread.watches.filter(user=request.user) %}
                      {% set watch = _('You are watching this thread') %}
                      <input type="hidden" name="watch" value="no" />
                      <a class="yes" title="{{ watch }}"></a>
                    {% else %}
                      {% set watch = _('You are not watching this thread') %}
                      <input type="hidden" name="watch" value="yes" />
                      <a class="no" title="{{ watch }}"></a>
                    {% endif %}
                  </form>
              </div>
            {% endif %}
            <div class="title">
              {% trans thread_url=thread.get_absolute_url(),
                       thread_title=thread.title,
                       document_discussion_url=url('wiki.discuss.threads',thread.document.slug),
                       document=thread.document %}
                <a href="{{ thread_url }}">{{ thread_title }}</a><br>
                in <a href="{{ document_discussion_url }}">{{ document }}</a>
              {% endtrans %}
            </div>
            <div class="author"><a class="username" href="{{ profile_url(thread.creator) }}">{{ display_name(thread.creator) }}</a></div>
            <div class="replies">{{ thread.replies }}</div>
            <div class="last-post">
              <a href="{{ thread.last_post.get_absolute_url() }}">
                {{ datetimeformat(thread.last_post.created) }}
              </a><br/>
              {{ _('by <a class="username" href="{profile_url}">{username}</a>')|fe(profile_url=profile_url(thread.last_post.creator), username=display_name(thread.last_post.creator)) }}
            </div>
          </li>
        {% endfor %}
        </ol>
        {{ threads|paginator }}
      {% else %}
        <p>{{ _('There are no threads. Maybe you should create some!') }}</p>
      {% endif %}
    </article>
  </div>
{% endblock %}
